#include "stdafx.h"
#include "SKPipeline.h"
#include "Builder.h"
#include "Differencer.h"
#include "Decider.h"
#include "Solver.h"
#include "CopyKnot.h"
#include "UpdateTree.h"
#include "ShowKnot.h"
#include "MoveKnot.h"
#include "RotateNode.h"
#include "Animation.h"
#include "SelectNode.h"
#include "DragNode.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif

CSKInfo::CSKInfo()
: m_UnitFrameCount(24)
{
}

CSKInfo::~CSKInfo()
{
	for (Frames::iterator it = m_Frames.begin();
		it != m_Frames.end(); it ++)
	{
		delete *it;
		*it = NULL;
	}
	m_Frames.clear();
}

void CSKInfo::Reset()
{
	m_oTimeline.Reset();
	m_streams.clear();
	for (Frames::iterator it = m_Frames.begin();
		it != m_Frames.end(); it ++)
	{
		delete *it;
		*it = NULL;
	}
	m_Frames.clear();
}


CSKFactory::CSKFactory()
: m_pSKInstance(NULL)
{
}

CSKFactory::~CSKFactory()
{
}

ISKPipeline* CSKFactory::CreateInstance(SKOperType eType)
{
	CProcessDraft* pSKDraft = new CProcessDraft();
	m_pSKInstance = NULL;

	switch (eType)
	{
	case eLoadFile:
		m_pSKInstance = new CBuilder(m_pSKInstance, pSKDraft);
		m_pSKInstance = new CUpdateTree(m_pSKInstance, pSKDraft);
		m_pSKInstance = new CShowKnot(m_pSKInstance, pSKDraft);
		break;

	case eCopyKnot:
		m_pSKInstance = new CCopyKnot(m_pSKInstance, pSKDraft);
		m_pSKInstance = new CUpdateTree(m_pSKInstance, pSKDraft);
		break;

	case eSolveAll:
		m_pSKInstance = new CDifferencer(m_pSKInstance, pSKDraft);
		m_pSKInstance = new CDecider(m_pSKInstance, pSKDraft);
		m_pSKInstance = new CSolver(m_pSKInstance, pSKDraft);
		break;

	case eUpdateTree:
		m_pSKInstance = new CUpdateTree(m_pSKInstance, pSKDraft);
		m_pSKInstance = new CShowKnot(m_pSKInstance, pSKDraft);
		break;

	case eMoveKnot:
		/*m_pSKInstance = new CMoveKnot(m_pSKInstance, pSKDraft);
		m_pSKInstance = new CShowKnot(m_pSKInstance, pSKDraft);*/
		break;

	case eRotateNode:
		m_pSKInstance = new CRotateNode(m_pSKInstance, pSKDraft);
		//m_pSKInstance = new CShowKnot(m_pSKInstance, pSKDraft);
		break;

	case eInvokeAnimation:
		m_pSKInstance = new CAnimation(m_pSKInstance, pSKDraft);
		break;

	case eSelectNode:
		m_pSKInstance = new CSelectNode(m_pSKInstance, pSKDraft);
		break;

	case eDragNode:
		m_pSKInstance = new CDragNode(m_pSKInstance, pSKDraft);
		break;
	}

	return m_pSKInstance;
}